/**
 * 参数设置管理初始化
 */
var distinguishList = {
    id: "distinguishListTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
distinguishList.initColumn = function () {
    var columns = [
        {field: 'selectItem',radio: true},
        {title: '用户ID', field: 'user_id', align: 'center', valign: 'middle',visible:false},
        {title: '用户账号', field: 'phone', align: 'center', valign: 'middle'},
        {title: '提交时间', field: 'add_time', align: 'center', valign: 'middle'},
        {title: '身份证号码', field: 'num', align: 'center', valign: 'middle'},
        {title: '正面认证图像 ', field: 'img', align: 'center', valign: 'middle',formatter: function (value, row, index) {
        	return '<img src="'+value+'" width="200px" height="100px"  />';
        }},
        {title: '背面认证图像', field: 'back_img', align: 'center', valign: 'middle',formatter: function (value, row, index) {
        	return '<img src="'+value+'"  width="200px" height="100px" />';
        }},
        {title: '状态', field: 'auth', align: 'center', valign: 'middle',formatter: function (value, row, index) {
        	 if(value=='1')
        	 {
        			return '审核成功';
        	 }else if(value=='2')
        	 {
        			return '待审核';
        	 }
        	 else if(value=='3')
        	 {
        			return '审核失败';
        	 }
        
        }},
        {title: '操作', field: 'Button', align: 'center', valign: 'middle',events:operateEvents,formatter: function (value, row, index) {
        	var html='';
        	if(row.auth=='2')
        	{
        		html='<input class="btn btn-success" id="passBtn" style="margin-right:5px" type="button" value="通过"><input class="btn btn-danger" id="reject_btn" style="margin-right:5px" type="button" value="驳回">';
        	}
        	html+='<input class="btn btn-default" type="button" id="search_img" value="查看原图"/>';
        	return html;
           
       }}
    ]
    return columns;
};

window.operateEvents={
		"click #search_img":function(e,value,row,index)
		{
			parent.layer.confirm("请选择要查看的原图", {
		            btn: ['正面', '反面']
		        }, function (index) {
                    Feng.infoDetail("查看原图","<img src='"+row.img+"'/>");
		            parent.layer.close(index);
		        }, function (index) {
		            Feng.infoDetail("查看原图","<img src='"+row.back_img+"'/>");
		             parent.layer.close(index);
		        });
				
		},
		"click #passBtn":function(e,value,row,index)
		{
		    //提交信息
		    var ajax = new $ax(Feng.ctxPath + "/distinguish/changeStatus", function (data) {
		        Feng.success("操作成功!");
		        distinguishList.table.refresh();
		    }, function (data) {
		        Feng.error("操作失败!" + data.responseJSON.message + "!");
		    });
		    ajax.set({"user_id":row.user_id,"status":"1"});
		    ajax.start();
		},
		"click #reject_btn":function(e,value,row,index)
		{
		    //提交信息
		    var ajax = new $ax(Feng.ctxPath + "/distinguish/changeStatus", function (data) {
		        Feng.success("操作成功!");
		        distinguishList.table.refresh();
		    }, function (data) {
		        Feng.error("操作失败!" + data.responseJSON.message + "!");
		    });
		    ajax.set({"user_id":row.user_id,"status":"3","error_info":"上传的身份证信息、手写日期不清晰或信息有误。"});
		    ajax.start();
		}
		
};


/**
 * 检查是否选中
 */
distinguishList.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中需要修改的记录！");
        return false;
    }else{
        return true;

    }
};

/**
 * 查询参数设置列表
 */
distinguishList.search = function () {
    var queryData = {};
    queryData['phone'] = $("#phone").val();
    queryData['status'] = $("#status").val();
    queryData['startTime'] = $("#startTime").val().replace("/","-");
    if($("#startTime").val() != "") {
        if($("#endTime").val() == "") {
            Feng.error("请选择结束时间！");
            return false;
        }else{
            queryData['endTime'] = $("#endTime").val().replace("/","-");
        }
    }
    
    
    distinguishList.table.refresh({query: queryData});
};


$(function () {
    $("#startTime").attr('type','date');
    $("#endTime").attr('type','date');
    var defaultColunms = distinguishList.initColumn();
    var table = new BSTable(distinguishList.id, "/distinguish/list", defaultColunms);
    table.setPaginationType("server");
    distinguishList.table = table.init();  
});



